package com.pkutech.carcasher.utils;

/**
 * @Title StringUtils.java
 * @fileName StringUtils.java
 * @Description TODO
 * @author guoqiang
 * @createDate 2013-12-31
 * @version 1.0
 */
public class StringUtils extends org.apache.commons.lang.StringUtils {
    
    /**
	 * 判断指定字符串是否null或空串
	 * @param str
	 * @return
	 */
	public static boolean isEmptyOrWhitespaceOnly(String str) {
		if (str != null && !"".equals(str.trim())) return false;
		return true;
	}
	
	/***
	 * 验证字符串是否为null
	 * @param str
	 * @return
	 */
	public static boolean isEmpty(String str) {
		if (str != null) return false;
		return true;
	}
	
	/** 判断str 是否为null 或者 为 空字符串(trim后)
	 * @param str
	 * @return
	 */
    public static final boolean isNullOrEmpty(String str){
    	if(str==null)return true;
    	if("".equals(str.trim()))return true;
    	return false;
    }
	
    /**
     * 转成UTF-8编码格式的字符串
     * @param s
     * @return
     */
	public static String toUtf8String(String s) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			if (c >= 0 && c <= 255) {
				sb.append(c);
			} else {
				byte[] b;
				try {
					b = Character.toString(c).getBytes("utf-8");
				} catch (Exception ex) {
					System.out.println(ex);
					b = new byte[0];
				}
				for (int j = 0; j < b.length; j++) {
					int k = b[j];
					if (k < 0)
						k += 256;
					sb.append("%" + Integer.toHexString(k).toUpperCase());
				}
			}
		}
		return sb.toString();
	}
	
	public static final String getSpringName(Class<?> cls){    	
    	return cls.getSimpleName().substring(0,1).toLowerCase()+cls.getSimpleName().substring(1);
    }
    
}